%define _EXCEPTIONS_EXTERN_OR_GLOBAL_ 1 
%include"../include/exceptions.mac" 

;interrupt and exception handler routines  
[section .text] 
;int 0:divide error  
;no error code 
_divide_error: 
	push handle_divide_error ;push address of error handle routines  
	jmp no_error_code  

;int 1:debug exception 
;no error code 
_debug_exception: 
	push handle_debug_exception 
	jmp no_error_code  

;int 2:NMI interrupt 
;error code:not applicable 
_nmi_intr: 
	push handle_nmi_intr 
	jmp no_error_code  

;int 3:Breakpoint Exception 
;error code:none 
_breakpoint:  
	push handle_breakpoint  
	jmp no_error_code  

;int 4:Overflow Exception 
;error code:none 
_overflow: 
	push handle_overflow 
	jmp no_error_code  

;int 5:BOUND Range Exceeded Exception  
;error code:none 
_bound_range_exceeded: 
	push handle_bound_range_exceeded 
	jmp no_error_code  

;int 6:invalid opcode Exception  
;error code:none 
_invalid_opcode: 
	push handle_invalid_opcode 
	jmp no_error_code  

;int 7:Devide Not Available Exception 
;error code:none 
_device_not_available: 
	push handle_device_not_available 
	jmp no_error_code  

;int 8:Double Fault Exception 
;error code:Zero. 
_double_fault:  
	push handle_double_fault 
	jmp error_code 

;int 9:Coprocessor Segment Overrun 
;error code:none. 
_coprocessor_seg_overrun: 
	push handle_coprocessor_seg_overrun 
	jmp no_error_code  

;int 10:invalid TSS Exception 
;error code:Yes 
_invalid_tss: 
	push handle_invalid_tss 
	jmp error_code  

;int 11:Segment Not Present 
;error code:Yes
_segment_not_present: 
	push handle_segment_not_present 
	jmp error_code  

;int 12:Stack Fault Exception 
;error code:yes 
_stack_fault: 
	push handle_stack_fault 
	jmp error_code 

;int 13:General Protection Exception 
;error code:yes 
_general_protection: 
	push handle_general_protection 
	jmp error_code   

;int 14:Page Fault Exception 
;error code:yes 
_page_fault: 
	push handle_page_fault 
	jmp error_code  

;int 16:x87 FPU Foating-Point Error  
;error code:none 
_x87_fpu: 
	push handle_x87_fpu 
	jmp no_error_code 

;int 17:Alignment Check Exception 
;error code:yes 
_alignment_check:	
	push handle_alignment_check 
	jmp error_code 

;int 18:Machine-Check Exception 
;error code:none. 
_machine_check:		
	push handle_machine_check
	jmp no_error_code  

;int 19:SIMD Floating-Point Exception 
;error code:none. 
_simd: 
	push handle_simd 
	jmp no_error_code  

;reserved 
_reserved: 
	push handle_reserved 
	jmp no_error_code  
	
no_error_code: 
	push ebp 
	mov ebp,esp 

	;push error code and eip as parameter to error handle routines   
	push 0 ;0 as error code 
	push dword[ebp+8] ;push eip  
	call dword[ebp+4] ;call error handle routine   

	pop ebp 
	add esp,0x04 ;clean up routine's address  
	iret    

error_code: 
	push ebp 

	;push error code and eip and parameter  
	push dword[ebp+8] ;error code 
	push dword[ebp+12] ;eip  
	call dword[ebp+4] ;call error handle routines  

	pop ebp 
	add esp,0x04 ;clean up routine's address  
	iret 
